/* 
 * Create new calendar
 */

// Create the calendar service object
var calendarService = new google.gdata.calendar.CalendarService('GoogleInc-jsguide-1.0');

// The default "owncalendars" feed is used to insert calendar to the logged-in user
var feedUri = 'http://www.google.com/calendar/feeds/default/owncalendars/full';

// Create an instance of CalendarEntry, representing the new calendar
var entry = new google.gdata.calendar.CalendarEntry();

// Set the calendar title
entry.setTitle(google.gdata.Text.create('JS-Client: insert calendar'));

// Set the calendar summary
var summary = new google.gdata.Text();
summary.setText('This is a test calendar created by JS Client');
entry.setSummary(summary);

// Set the calendar timezone
var timeZone = new google.gdata.calendar.TimeZoneProperty();
timeZone.setValue('America/Los_Angeles');
entry.setTimeZone(timeZone);

// Set the calendar location
var where = new google.gdata.Where();
where.setLabel('Mountain View, CA');
where.setValueString('Mountain View, CA');
entry.addLocation(where);

// Set the calendar to be visible in the Google Calendar UI
var hidden = new google.gdata.calendar.HiddenProperty();
hidden.setValue(false);
entry.setHidden(hidden);

// Set the color that represent this calendar in the Google Calendar UI
var color = new google.gdata.calendar.ColorProperty();
color.setValue('#2952A3');
entry.setColor(color);

// The callback method that will be called after a successful 
// insertion from insertEntry()
var callback = function(result) {
  PRINT('calendar created!');
}

// Error handler will be invoked if there is an error from insertEntry()
var handleError = function(error) {
  PRINT(error);
}

// Submit the request using the calendar service object
calendarService.insertEntry(feedUri, entry, callback, 
    handleError, google.gdata.calendar.CalendarEntry);
